/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.util.ArrayList;

/**
 *
 * @author user
 */
public class ChatUsers extends ArrayList<ChatUser> {

    public ChatUser find(int userId) {
        ChatUser chatUser;

        for (int i = 0; i < this.size(); ++i) {
            chatUser = this.get(i);

            if (chatUser.userId == userId) {
                // Found
                return chatUser;
            }
        }

        // Not Found
        return null;
    }

    public void add(String sender, int senderId, int recieverId, String content) {        
        ChatUser chatUser = find(recieverId);
        Chat chat;

        if (chatUser == null) {
            // Create new
            chatUser = new ChatUser(recieverId);
            add(chatUser);
        }

        chat = new Chat();
        chat.senderName = sender;
        chat.content = content;
        chat.timeStamp = System.currentTimeMillis();
        chat.senderId = senderId;
        chatUser.add(chat);
        
        chat.id = chatUser.size()-1;        

        System.out.println(chatUser.toString());
    }
}
